package cn.wolfcode.controller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result selAll(){
        List<Dept> depts = deptService.selectAll();
        return Result.success(depts);
    }

    @DeleteMapping("/{id}")
    public Result delById(@PathVariable Long id){
        deptService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result save(@RequestBody Dept dept){
        deptService.save(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selById(@PathVariable Long id){
        Dept dept = deptService.selectById(id);
        return Result.success(dept);

    }

    @PutMapping
    public Result update(@RequestBody Dept dept){
            deptService.update(dept);
            return Result.success();

    }
}
